<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: simpleMotionCommands.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('simpleMotionCommands_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">simpleMotionCommands.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>example showing how to connect and send basic motion commands to the robotARIA provides two levels of robot motion control, direct motion commands, and actions. This example shows direct motion commands. See actionExample.cpp, actionGroupExample.cpp, and others for examples on how to use actions. Actions provide a more modular way of performing more complex motion behaviors than the simple imperitive style used here.</p>
<p>See the <a class="el" href="classArRobot.html" title="Central class for communicating with and operating the robot. ">ArRobot</a> class documentation, as well as the overview of robot motion, for more information.</p>
<p>WARNING: this program does no sensing or avoiding of obstacles, the robot WILL collide with any objects in the way! Make sure the robot has about 2-3 meters of free space around it before starting the program.</p>
<p>This program will work either with the MobileSim simulator or on a real robot's onboard computer. (Or use -remoteHost to connect to a wireless ethernet-serial bridge.)</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line"></div><div class="line">  <a name="a0"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a1"></a><a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line">  <a name="_a2"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a3"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line"></div><div class="line">  <a name="a4"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a5"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;WARNING: this program does no sensing or avoiding of obstacles, the robot WILL collide with any objects in the way! Make sure the robot has approximately 3 meters of free space on all sides.&quot;</span>);</div><div class="line"></div><div class="line">  <span class="comment">// ArRobotConnector connects to the robot, get some initial data from it such as type and name,</span></div><div class="line">  <span class="comment">// and then loads parameter files for this robot.</span></div><div class="line">  <a name="_a6"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> robotConnector(&amp;parser, &amp;robot);</div><div class="line">  <span class="keywordflow">if</span>(!robotConnector.<a name="a7"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;simpleMotionCommands: Could not connect to the robot.&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span>(parser.<a name="a8"></a><a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">    {</div><div class="line">        <a name="a9"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">        <a name="a10"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">        <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line">  }</div><div class="line">  <span class="keywordflow">if</span> (!<a name="a11"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    <span class="keywordflow">return</span> 1;</div><div class="line">  }</div><div class="line">  </div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a12"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Connected.&quot;</span>);</div><div class="line"></div><div class="line">  <span class="comment">// Start the robot processing cycle running in the background.</span></div><div class="line">  <span class="comment">// True parameter means that if the connection is lost, then the </span></div><div class="line">  <span class="comment">// run loop ends.</span></div><div class="line">  robot.<a name="a13"></a><a class="code" href="classArRobot.html#a3c3d878cfd11a2ef91230005a83bfcaa">runAsync</a>(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">  <span class="comment">// Print out some data from the SIP.  </span></div><div class="line"></div><div class="line">  <span class="comment">// We must &quot;lock&quot; the ArRobot object</span></div><div class="line">  <span class="comment">// before calling its methods, and &quot;unlock&quot; when done, to prevent conflicts</span></div><div class="line">  <span class="comment">// with the background thread started by the call to robot.runAsync() above.</span></div><div class="line">  <span class="comment">// See the section on threading in the manual for more about this.</span></div><div class="line">  <span class="comment">// Make sure you unlock before any sleep() call or any other code that will</span></div><div class="line">  <span class="comment">// take some time; if the robot remains locked during that time, then</span></div><div class="line">  <span class="comment">// ArRobot&#39;s background thread will be blocked and unable to communicate with</span></div><div class="line">  <span class="comment">// the robot, call tasks, etc.</span></div><div class="line">  </div><div class="line">  robot.<a name="a14"></a><a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Pose=(%.2f,%.2f,%.2f), Trans. Vel=%.2f, Rot. Vel=%.2f, Battery=%.2fV&quot;</span>,</div><div class="line">    robot.<a name="a15"></a><a class="code" href="group__easy.html#ga4c994926aaefc4c86380f1a74e508a76">getX</a>(), robot.<a name="a16"></a><a class="code" href="group__easy.html#ga9164db66102fdf9d422feefdadffca92">getY</a>(), robot.<a name="a17"></a><a class="code" href="group__easy.html#gaefe932449c50da9ca0f8084cd9639583">getTh</a>(), robot.<a name="a18"></a><a class="code" href="group__easy.html#gad75dbd9aede7b7f57c9a38902b8aa1ce">getVel</a>(), robot.<a name="a19"></a><a class="code" href="group__easy.html#gac2abfcd681cccdc2cf091d2901f0ba5b">getRotVel</a>(), robot.<a name="a20"></a><a class="code" href="classArRobot.html#a8d1637a9f3d37e55768d2aa1c8c272d6">getBatteryVoltage</a>());</div><div class="line">  robot.<a name="a21"></a><a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line"></div><div class="line">  <span class="comment">// Sleep for 3 seconds.</span></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Will start driving in 3 seconds...&quot;</span>);</div><div class="line">  <a name="a22"></a><a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(3000);</div><div class="line"></div><div class="line">  <span class="comment">// Set forward velocity to 50 mm/s</span></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Driving forward at 250 mm/s for 5 sec...&quot;</span>);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  robot.<a name="a23"></a><a class="code" href="group__easy.html#gaa3657bebab0086dd14ed0c8c3f76dc8b">enableMotors</a>();</div><div class="line">  robot.<a name="a24"></a><a class="code" href="group__easy.html#gac4c369f0f8d8a41f2b3f2290bdcbb03c">setVel</a>(250);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line">  <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(5000);</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Stopping.&quot;</span>);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  robot.<a name="a25"></a><a class="code" href="group__easy.html#gac354fe63f9e58b33343f38923f1588fd">stop</a>();</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line">  <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1000);</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Rotating at 10 deg/s for 5 sec...&quot;</span>);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  robot.<a name="a26"></a><a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">setRotVel</a>(10);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line">  <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(5000);</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Rotating at -10 deg/s for 10 sec...&quot;</span>);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  robot.<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">setRotVel</a>(-10);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line">  <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(10000);</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Driving forward at 150 mm/s for 5 sec...&quot;</span>);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  robot.<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">setRotVel</a>(0);</div><div class="line">  robot.<a class="code" href="group__easy.html#gac4c369f0f8d8a41f2b3f2290bdcbb03c">setVel</a>(150);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line">  <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(5000);</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Stopping.&quot;</span>);</div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  robot.<a class="code" href="group__easy.html#gac354fe63f9e58b33343f38923f1588fd">stop</a>();</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line">  <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1000);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Other motion command functions include move(), setHeading(),</span></div><div class="line">  <span class="comment">// setDeltaHeading().  You can also adjust acceleration and deceleration</span></div><div class="line">  <span class="comment">// values used by the robot with setAccel(), setDecel(), setRotAccel(),</span></div><div class="line">  <span class="comment">// setRotDecel().  See the ArRobot class documentation for more.</span></div><div class="line"></div><div class="line">  </div><div class="line">  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Pose=(%.2f,%.2f,%.2f), Trans. Vel=%.2f, Rot. Vel=%.2f, Battery=%.2fV&quot;</span>,</div><div class="line">    robot.<a class="code" href="group__easy.html#ga4c994926aaefc4c86380f1a74e508a76">getX</a>(), robot.<a class="code" href="group__easy.html#ga9164db66102fdf9d422feefdadffca92">getY</a>(), robot.<a class="code" href="group__easy.html#gaefe932449c50da9ca0f8084cd9639583">getTh</a>(), robot.<a class="code" href="group__easy.html#gad75dbd9aede7b7f57c9a38902b8aa1ce">getVel</a>(), robot.<a class="code" href="group__easy.html#gac2abfcd681cccdc2cf091d2901f0ba5b">getRotVel</a>(), robot.<a class="code" href="classArRobot.html#a8d1637a9f3d37e55768d2aa1c8c272d6">getBatteryVoltage</a>());</div><div class="line">  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line"></div><div class="line">  </div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Ending robot thread...&quot;</span>);</div><div class="line">  robot.<a name="a27"></a><a class="code" href="group__easy.html#gaff02cf7043c2e7239ec6b6e11ff6b146">stopRunning</a>();</div><div class="line"></div><div class="line">  <span class="comment">// wait for the thread to stop</span></div><div class="line">  robot.<a name="a28"></a><a class="code" href="group__easy.html#ga95201be7c39b521983b51e6f5d9303e4">waitForRunExit</a>();</div><div class="line"></div><div class="line">  <span class="comment">// exit</span></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;simpleMotionCommands: Exiting.&quot;</span>);</div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
